#include "cCamera.h"


cCamera::cCamera( wxWindow* parent, wxWindowID id, const wxString& title, const wxPoint& pos, const wxSize& size, long style ) : wxFrame( parent, id, title, pos, size, style )
{
	this->SetSizeHints( wxDefaultSize, wxDefaultSize );
	
	m_menubar3 = new wxMenuBar( 0 );
	cameraMenu = new wxMenu();
	wxMenuItem* exitMenuItem;
	exitMenuItem = new wxMenuItem( cameraMenu, wxID_ANY, wxString( wxT("exit") ) , wxEmptyString, wxITEM_NORMAL );
	cameraMenu->Append( exitMenuItem );
	
	m_menubar3->Append( cameraMenu, wxT("File") ); 
	
	this->SetMenuBar( m_menubar3 );
	
	wxBoxSizer* bSizer3;
	bSizer3 = new wxBoxSizer( wxVERTICAL );
	
	wxGridBagSizer* gbSizer1;
	gbSizer1 = new wxGridBagSizer( 0, 0 );
	gbSizer1->AddGrowableCol( 2 );
	gbSizer1->AddGrowableRow( 2 );
	gbSizer1->SetFlexibleDirection( wxBOTH );
	gbSizer1->SetNonFlexibleGrowMode( wxFLEX_GROWMODE_SPECIFIED );
	
	wxStaticBoxSizer* sbSizer1;
	sbSizer1 = new wxStaticBoxSizer( new wxStaticBox( this, wxID_ANY, wxT("Camera Options") ), wxHORIZONTAL );
	
	wxBoxSizer* bSizer16;
	bSizer16 = new wxBoxSizer( wxHORIZONTAL );
	
	wxString resolutionRadioBoxChoices[] = { wxT("320x240"), wxT("640x480") };
	int resolutionRadioBoxNChoices = sizeof( resolutionRadioBoxChoices ) / sizeof( wxString );
	resolutionRadioBox = new wxRadioBox( this, wxID_ANY, wxT("Resolution"), wxDefaultPosition, wxDefaultSize, resolutionRadioBoxNChoices, resolutionRadioBoxChoices, 1, wxRA_SPECIFY_COLS );
	resolutionRadioBox->SetSelection( 0 );
	bSizer16->Add( resolutionRadioBox, 0, wxALL, 5 );
	
	startCameraButton = new wxToggleButton( this, wxID_ANY, wxT("Start Camera"), wxDefaultPosition, wxDefaultSize, 0 );
	bSizer16->Add( startCameraButton, 0, wxALL|wxALIGN_CENTER_HORIZONTAL, 5 );
	
	sbSizer1->Add( bSizer16, 1, wxEXPAND, 5 );
	
	gbSizer1->Add( sbSizer1, wxGBPosition( 0, 2 ), wxGBSpan( 1, 1 ), wxEXPAND, 5 );
	
	wxStaticBoxSizer* sbSizer2;
	sbSizer2 = new wxStaticBoxSizer( new wxStaticBox( this, wxID_ANY, wxT("Stereo Options") ), wxHORIZONTAL );
	
	wxBoxSizer* bSizer11;
	bSizer11 = new wxBoxSizer( wxVERTICAL );
	
	wxBoxSizer* bSizer10;
	bSizer10 = new wxBoxSizer( wxHORIZONTAL );
	
	wxBoxSizer* bSizer5;
	bSizer5 = new wxBoxSizer( wxVERTICAL );
	
	extrinsicsStaticText = new wxStaticText( this, wxID_ANY, wxT("Extrinsics File"), wxDefaultPosition, wxDefaultSize, 0 );
	extrinsicsStaticText->Wrap( -1 );
	bSizer5->Add( extrinsicsStaticText, 0, wxALL, 5 );
	
	extrinsicsTextCtrl = new wxTextCtrl( this, wxID_ANY, wxT("extrinsics320.yml"), wxDefaultPosition, wxDefaultSize, 0 );
	extrinsicsTextCtrl->SetMinSize( wxSize( 100,-1 ) );
	
	bSizer5->Add( extrinsicsTextCtrl, 0, wxALL, 5 );
	
	bSizer10->Add( bSizer5, 1, wxEXPAND, 5 );
	
	wxBoxSizer* bSizer4;
	bSizer4 = new wxBoxSizer( wxVERTICAL );
	
	intrinsicsStaticText = new wxStaticText( this, wxID_ANY, wxT("Intrinsics file"), wxDefaultPosition, wxDefaultSize, 0 );
	intrinsicsStaticText->Wrap( -1 );
	bSizer4->Add( intrinsicsStaticText, 0, wxALL, 5 );
	
	intrinsicsTextCtrl = new wxTextCtrl( this, wxID_ANY, wxT("intrinsics320.yml"), wxDefaultPosition, wxDefaultSize, 0 );
	intrinsicsTextCtrl->SetMinSize( wxSize( 100,-1 ) );
	
	bSizer4->Add( intrinsicsTextCtrl, 0, wxALL, 5 );
	
	bSizer10->Add( bSizer4, 1, wxEXPAND, 5 );
	
	calculateStereoButton = new wxToggleButton( this, wxID_ANY, wxT("Calculate Stereo"), wxDefaultPosition, wxDefaultSize, 0 );
	bSizer10->Add( calculateStereoButton, 0, wxALL|wxALIGN_CENTER_VERTICAL, 5 );
	
	wxString algorithmRadioBoxChoices[] = { wxT("bm"), wxT("sgbm"), wxT("hh"), wxT("bpGPU"), wxT("csbpGPU"), wxT("bmGPU") };
	int algorithmRadioBoxNChoices = sizeof( algorithmRadioBoxChoices ) / sizeof( wxString );
	algorithmRadioBox = new wxRadioBox( this, wxID_ANY, wxT("Stereo Algorithm"), wxDefaultPosition, wxDefaultSize, algorithmRadioBoxNChoices, algorithmRadioBoxChoices, 1, wxRA_SPECIFY_COLS );
	algorithmRadioBox->SetSelection( 0 );
	bSizer10->Add( algorithmRadioBox, 0, wxALL, 5 );
	
	bSizer11->Add( bSizer10, 1, wxEXPAND, 5 );
	
	wxBoxSizer* bSizer12;
	bSizer12 = new wxBoxSizer( wxHORIZONTAL );
	
	wxBoxSizer* bSizer13;
	bSizer13 = new wxBoxSizer( wxVERTICAL );
	
	m_staticText11 = new wxStaticText( this, wxID_ANY, wxT("Number of Disparities"), wxDefaultPosition, wxDefaultSize, 0 );
	m_staticText11->Wrap( -1 );
	bSizer13->Add( m_staticText11, 0, wxALIGN_CENTER|wxALL, 5 );
	
	wxString dispChoiceChoices[] = { wxT("16"), wxT("32"), wxT("48"), wxT("64"), wxT("80"), wxT("96"), wxT("112"), wxT("128") };
	int dispChoiceNChoices = sizeof( dispChoiceChoices ) / sizeof( wxString );
	dispChoice = new wxChoice( this, wxID_ANY, wxDefaultPosition, wxDefaultSize, dispChoiceNChoices, dispChoiceChoices, 0 );
	dispChoice->SetSelection( 1 );
	bSizer13->Add( dispChoice, 0, wxALL|wxALIGN_CENTER_HORIZONTAL, 5 );
	
	bSizer12->Add( bSizer13, 1, wxEXPAND, 5 );
	
	wxBoxSizer* bSizer14;
	bSizer14 = new wxBoxSizer( wxVERTICAL );
	
	m_staticText12 = new wxStaticText( this, wxID_ANY, wxT("SAD Window Size"), wxDefaultPosition, wxDefaultSize, 0 );
	m_staticText12->Wrap( -1 );
	bSizer14->Add( m_staticText12, 0, wxALL|wxALIGN_CENTER_HORIZONTAL, 5 );
	
	wxString SADChoiceChoices[] = { wxT("3"), wxT("6"), wxT("9"), wxT("12"), wxT("15") };
	int SADChoiceNChoices = sizeof( SADChoiceChoices ) / sizeof( wxString );
	SADChoice = new wxChoice( this, wxID_ANY, wxDefaultPosition, wxDefaultSize, SADChoiceNChoices, SADChoiceChoices, 0 );
	SADChoice->SetSelection( 2 );
	bSizer14->Add( SADChoice, 0, wxALL|wxALIGN_CENTER_HORIZONTAL, 5 );
	
	bSizer12->Add( bSizer14, 1, wxALIGN_CENTER|wxALIGN_CENTER_HORIZONTAL|wxEXPAND, 5 );
	
	bSizer11->Add( bSizer12, 1, wxEXPAND, 5 );
	
	sbSizer2->Add( bSizer11, 1, wxEXPAND, 5 );
	
	gbSizer1->Add( sbSizer2, wxGBPosition( 0, 1 ), wxGBSpan( 1, 1 ), wxEXPAND, 5 );
	
	bSizer3->Add( gbSizer1, 0, wxALIGN_RIGHT|wxEXPAND|wxALL, 5 );
	
	wxStaticBoxSizer* sbSizer3;
	sbSizer3 = new wxStaticBoxSizer( new wxStaticBox( this, wxID_ANY, wxT("Saving Options") ), wxVERTICAL );
	
	wxBoxSizer* bSizer131;
	bSizer131 = new wxBoxSizer( wxHORIZONTAL );
	
	ssButton = new wxButton( this, wxID_ANY, wxT("Screenshot"), wxDefaultPosition, wxDefaultSize, 0 );
	bSizer131->Add( ssButton, 0, wxALL|wxALIGN_CENTER_HORIZONTAL, 5 );
	
	saveVideoButton = new wxToggleButton( this, wxID_ANY, wxT("Save Video"), wxDefaultPosition, wxDefaultSize, 0 );
	bSizer131->Add( saveVideoButton, 0, wxALL|wxALIGN_CENTER_HORIZONTAL, 5 );
	
	wxBoxSizer* bSizer141;
	bSizer141 = new wxBoxSizer( wxVERTICAL );
	
	leftVCheckBox = new wxCheckBox( this, wxID_ANY, wxT("Left Video"), wxDefaultPosition, wxDefaultSize, 0 );
	leftVCheckBox->SetValue(true); 
	bSizer141->Add( leftVCheckBox, 0, wxALL|wxALIGN_CENTER_HORIZONTAL, 5 );
	
	rightVCheckBox = new wxCheckBox( this, wxID_ANY, wxT("Right Video"), wxDefaultPosition, wxDefaultSize, 0 );
	bSizer141->Add( rightVCheckBox, 0, wxALL|wxALIGN_CENTER_HORIZONTAL, 5 );
	
	stereoVCheckBox = new wxCheckBox( this, wxID_ANY, wxT("Stereo Video"), wxDefaultPosition, wxDefaultSize, 0 );
	stereoVCheckBox->SetValue(true); 
	bSizer141->Add( stereoVCheckBox, 0, wxALL|wxALIGN_CENTER_HORIZONTAL, 5 );
	
	bSizer131->Add( bSizer141, 1, 0, 5 );
	
	wxBoxSizer* bSizer15;
	bSizer15 = new wxBoxSizer( wxHORIZONTAL );
	
	m_staticText10 = new wxStaticText( this, wxID_ANY, wxT("Video/Screen Name:"), wxDefaultPosition, wxDefaultSize, 0 );
	m_staticText10->Wrap( -1 );
	bSizer15->Add( m_staticText10, 0, wxALL|wxALIGN_CENTER_VERTICAL, 5 );
	
	saveTextCtrl = new wxTextCtrl( this, wxID_ANY, wxT("video"), wxDefaultPosition, wxDefaultSize, 0 );
	bSizer15->Add( saveTextCtrl, 0, wxALL|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 5 );
	
	bSizer131->Add( bSizer15, 1, wxEXPAND, 5 );
	
	sbSizer3->Add( bSizer131, 1, wxEXPAND, 5 );
	
	bSizer3->Add( sbSizer3, 1, wxEXPAND, 5 );
	
	this->SetSizer( bSizer3 );
	this->Layout();
	bSizer3->Fit( this );
	
	this->Centre( wxBOTH );
	
	// Connect Events
	this->Connect( wxEVT_CLOSE_WINDOW, wxCloseEventHandler( cCamera::onClose ) );
	this->Connect( exitMenuItem->GetId(), wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler( cCamera::onExit ) );
	resolutionRadioBox->Connect( wxEVT_COMMAND_RADIOBOX_SELECTED, wxCommandEventHandler( cCamera::onResolution ), NULL, this );
	startCameraButton->Connect( wxEVT_COMMAND_TOGGLEBUTTON_CLICKED, wxCommandEventHandler( cCamera::onStartCamera ), NULL, this );
	calculateStereoButton->Connect( wxEVT_COMMAND_TOGGLEBUTTON_CLICKED, wxCommandEventHandler( cCamera::onCalculateStereo ), NULL, this );
	algorithmRadioBox->Connect( wxEVT_COMMAND_RADIOBOX_SELECTED, wxCommandEventHandler( cCamera::onStereoRadioBox ), NULL, this );
	dispChoice->Connect( wxEVT_COMMAND_CHOICE_SELECTED, wxCommandEventHandler( cCamera::onDispChoice ), NULL, this );
	SADChoice->Connect( wxEVT_COMMAND_CHOICE_SELECTED, wxCommandEventHandler( cCamera::onSADChoice ), NULL, this );
	ssButton->Connect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( cCamera::onScreenshot ), NULL, this );
	saveVideoButton->Connect( wxEVT_COMMAND_TOGGLEBUTTON_CLICKED, wxCommandEventHandler( cCamera::onSaveVideo ), NULL, this );
}

cCamera::~cCamera()
{
	// Disconnect Events
	this->Disconnect( wxEVT_CLOSE_WINDOW, wxCloseEventHandler( cCamera::onClose ) );
	this->Disconnect( wxID_ANY, wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler( cCamera::onExit ) );
	resolutionRadioBox->Disconnect( wxEVT_COMMAND_RADIOBOX_SELECTED, wxCommandEventHandler( cCamera::onResolution ), NULL, this );
	startCameraButton->Disconnect( wxEVT_COMMAND_TOGGLEBUTTON_CLICKED, wxCommandEventHandler( cCamera::onStartCamera ), NULL, this );
	calculateStereoButton->Disconnect( wxEVT_COMMAND_TOGGLEBUTTON_CLICKED, wxCommandEventHandler( cCamera::onCalculateStereo ), NULL, this );
	algorithmRadioBox->Disconnect( wxEVT_COMMAND_RADIOBOX_SELECTED, wxCommandEventHandler( cCamera::onStereoRadioBox ), NULL, this );
	dispChoice->Disconnect( wxEVT_COMMAND_CHOICE_SELECTED, wxCommandEventHandler( cCamera::onDispChoice ), NULL, this );
	SADChoice->Disconnect( wxEVT_COMMAND_CHOICE_SELECTED, wxCommandEventHandler( cCamera::onSADChoice ), NULL, this );
	ssButton->Disconnect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( cCamera::onScreenshot ), NULL, this );
	saveVideoButton->Disconnect( wxEVT_COMMAND_TOGGLEBUTTON_CLICKED, wxCommandEventHandler( cCamera::onSaveVideo ), NULL, this );
	
}
